import decimal
from django.shortcuts import render,HttpResponse
# Create your views here.
from app.models import Book


def addbook(request):
    name=request.GET.get("name","")
    price =request.GET.get("price")
    isbn_no=request.GET.get("isbn_no")
    book=Book(name=name,price=decimal.Decimal(float(price)),isbn_no=isbn_no)
    book.save()
    return HttpResponse("------")

def showbook(request,bookid):
    book=[]
    try:
        book=Book.objects.get(id=bookid)
    except:
        print("1")

    if book:
        return render(request,"book.html",{"book":book})
    else:
        return HttpResponse("没有书")